﻿<%@ Page Language="C#" %>
<%@ Import Namespace= "System.Collections"%>
<%@ Import Namespace="System.Collections.Generic" %>

<%
    List<DTO.SanPhamDto> dsSanPham = BUS.SanPhamBus.LayDanhSachSanPham();
    int start = Int16.Parse(Request["start"]);
    int end = Int16.Parse(Request["end"]);
    Response.Write("<?xml version='1.0' encoding='utf-8'?>");
	Response.Write("<root>");
    String key;
    if (Request["key"] != null)
    {
        key = Request["key"];
        int count = BUS.SanPhamBus.LaySoLuongSanPhamTheoKey(key);
        Response.Write("<total>"+count+"</total>");  
        dsSanPham=BUS.SanPhamBus.LayDanhSachSanPhamTheoKeyPaging(start,end,key); 
    }
    else
    {
        Response.Write("<total>"+dsSanPham.Count+"</total>");
        dsSanPham = BUS.SanPhamBus.LayDanhSachSanPhamPaging(start,end);
    }
    Response.Write("<productlist>");
    
    foreach(DTO.SanPhamDto sp in dsSanPham)
    {
        Response.Write("<product>");
        Response.Write("<id>"+sp.ID+"</id>");
        Response.Write("<idloai>"+sp.IDLoai+"</idloai>");
        DTO.LoaiSanPhamDto loai = BUS.LoaiSanPhamBus.LayLoaiSanPhamTheoID(sp.IDLoai);
        Response.Write("<loai><![CDATA[" + loai.TenLoaiSanPham + "]]></loai>");
        Response.Write("<ten><![CDATA["+sp.TenSanPham+"]]></ten>");
        Response.Write("<hinh><![CDATA["+sp.Hinh+"]]></hinh>");
        Response.Write("<gia>" + sp.DonGia + "</gia>");
        Response.Write("<diem>" + sp.DiemBinhChon + "</diem>");
        Response.Write("<conlai>"+sp.SoLuongCon+"</conlai>");
        Response.Write("<daban>"+sp.SoLuongDaBan+"</daban>");
        Response.Write("<idkhuyenmai>"+sp.IDKhuyenMai+"</idkhuyenmai>");
        DTO.KhuyenMaiDto km = BUS.KhuyenMaiBus.LayKhuyenMaiTheoID(sp.IDKhuyenMai);
        
        Response.Write("<khuyenmai><![CDATA[" + km.HinhThuc + "]]></khuyenmai>");
        Response.Write("<idgiamgia>"+sp.IDGiamGia+"</idgiamgia>");
        DTO.GiamGiaDto giam = BUS.GiamGiaBus.LayGiamGiaTheoID(sp.IDGiamGia);
        //Response.Write("<giamgia>" + giam.MucGiam + "</giamgia>");
        Response.Write("<ngaynhap><![CDATA["+sp.NgayNhap+"]]></ngaynhap>");
        Response.Write("<idnhasx>"+sp.IDNhaSanXuat+"</idnhasx>");
        DTO.NhaSanXuatDto sx = BUS.NhaSanXuatBus.LayNhaSanXuat(sp.IDNhaSanXuat);
        Response.Write("<nhasx><![CDATA[" + sx.Ten + "]]></nhasx>");
        Response.Write("</product>");
    }
   
    Response.Write("</productlist>");
    Response.Write("</root>");
%>
